package com.gbq.qimo.servlet;

import com.gbq.qimo.pojo.PageBean;
import com.gbq.qimo.pojo.Student;
import com.gbq.qimo.pojo.Teacher;
import com.gbq.qimo.service.StudentService;
import com.gbq.qimo.service.TeacherService;
import com.gbq.qimo.service.impl.StudentServiceImpl;
import com.gbq.qimo.service.impl.TeacherServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @ClassName FindStudentByPageServlet
 * @Description TODO
 * @Author guobenqi
 * @Date 2021/5/29 23:46
 */
@WebServlet("/findStudentByPage")
public class FindStudentByPageServlet extends HttpServlet {
    private StudentService studentService = new StudentServiceImpl();
    private TeacherService teacherService = new TeacherServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        //1.获取参数
        String currentPage = request.getParameter("currentPage");//当前页码
        String rows = request.getParameter("rows");//每页显示条数

        if(currentPage == null || "".equals(currentPage)){

            currentPage = "1";
        }
        if(rows == null || "".equals(rows)){
            rows = "5";
        }
        //获取条件查询参数
        Map<String, String[]> condition = request.getParameterMap();

        PageBean<Student> students = studentService.findBookByPage(currentPage,rows,condition);
        request.setAttribute("students",students);
        request.setAttribute("condition",condition);



        List<Teacher> teacherList = teacherService.findAllTeacher();
        request.setAttribute("teacherList",teacherList);

        request.getRequestDispatcher("/admin.jsp").forward(request,response);
    }
}
